package com.yunji.generate.service;

import com.yunji.generate.common.ResultMessage;

import java.util.List;

/**
 * @author hushuang
 * @since 2019/9/23
 */
public interface IProcessCallback<T> {

    class Parameter<T> {

        public final int sequence;

        public final T source;

        public final long time;

        public final ResultMessage result;

        public Parameter() {
            this(null, 0);
        }

        public Parameter(T source, int sequence) {
            this(source, sequence, ResultMessage.success());
        }

        public Parameter(T source, int sequence, ResultMessage resultMessage) {
            this.source = source;
            this.sequence = sequence;
            this.time = System.currentTimeMillis();
            this.result = resultMessage;
        }
    }

    class ListParameter<T> extends Parameter<List<T>> {

        public ListParameter() {
            super();
        }

        public ListParameter(List<T> source) {
            super(source, source.size());
        }

        public ListParameter(List<T> source, ResultMessage resultMessage) {
            super(source, source.size(), resultMessage);
        }
    }

    /**
     * 处理开始
     */
    default void onProcessBegin(ListParameter<T> p) {
    }

    /**
     * 处理中，每生成一个实体类调用一次
     */
    default boolean onProcessing(Parameter<T> p) {
        return false;
    }

    /**
     * 处理结束
     */
    default void onProcessEnd(ListParameter<T> p) {
    }
}
